﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Relation.aspx.cs" Inherits="GeneratorPages_Relation" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>

    <script language="javascript" type="text/javascript">

        var concatenatedIds = "";
        var _isMultiSelect = false;
        // checkboxId - id kontrolki checkboxa
        // howManSeek - ile komórek należy przejść, aby pobrać wartość z klucza głównego
        function CheckElement(checkboxId, howManySeek, isMultiSelect) {
            _isMultiSelect = isMultiSelect;
            var checkBox = document.getElementById(checkboxId);
            var destinationElement = checkBox.parentNode.nextSibling;
            for (var counter = 1; counter < howManySeek; counter++) {
                destinationElement = destinationElement.nextSibling;
            }
            var clickedElementId = destinationElement.innerHTML;
            if (checkBox.checked) {
                concatenatedIds += clickedElementId + ";";
            }
            else {
                concatenatedIds = concatenatedIds.replace(clickedElementId + ";", "");
            }
        }

        function OnEnd() {
            if (_isMultiSelect) {
                if (concatenatedIds.length == 0) {
                    alert('Należy wybrać co najmniej jeden element');
                    return;
                }
            }
            else {
                if (concatenatedIds.length != 2) {
                    alert('Należy wybrać dokładnie jeden element');
                    return;                    
                }            
            }
            
            window.returnValue = concatenatedIds;
            window.close();           
            
        }
    
    </script>

    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel1" runat="server">
        </asp:Panel>
        <asp:HiddenField ID="listId" runat="server" />
        <asp:Button ID="btOk" runat="server" Text="Ok" OnClientClick="OnEnd();return false;" />
        <asp:Button ID="btCancel" runat="server" Text="Anuluj" OnClientClick="window.returnValue = ''; window.close();return false;" />
    </div>
    </form>
</body>
</html>
